package com.laicar.androidnfp51;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    AutoCompleteTextView txtSearch;
    List<People> mList;
    PeopleAdapter adapter;
    private People selectPerson;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mList=this.retrievePeople();
        txtSearch=findViewById(R.id.auto_name);
        adapter=new PeopleAdapter(this,R.layout.activity_main,R.id.lbl_name,mList);
        txtSearch.setAdapter(adapter);
        txtSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapaterView, View view, int position, long id) {
                selectPerson=(People)adapaterView.getItemAtPosition(position);
            }
        });
    }

    private List<People> retrievePeople() {
        List<People> list = new ArrayList<People>();
        list.add(new People("James","Bond",1));
        list.add(new People("Jason","Bourne",2));
        list.add(new People("Ethan","Hunt",3));
        list.add(new People("Sherlock","Holmes",4));
        list.add(new People("David","Beckham",5));
        list.add(new People("Bryan","Adams",6));
        list.add(new People("Arjen","Robben",7));
        list.add(new People("Van","Persie",8));
        list.add(new People("Zinedine","Zidane",9));
        list.add(new People("Luis","Figo",10));
        list.add(new People("John","Watson",11));
        return list;
    }
}
